﻿var TT_TP015="";
var TT_TP017="";
var TT_TP018="";
var TT_TP019="";
var TT_TP020="";
var TT_TP021="";
var TT_TP022="";
var TT_TP023="";
var TT_TP024="";
var TT_C0045="";
var TT_C0044="";
// 编辑字的div id
var TT_a="";
//显示时间的 div id
var TT_b="";
// Weeks
var TT_c="";
//  FromTimes
var TT_d="";
// ToTimes
var TT_e="";
var TT_C0053="";
var TT_TP315="";
var TT_C0050="";
var _TT_Week= new Array();
var _TT_FromTime= new Array();
var _TT_ToTime= new Array();
function $TTime$(a,b,c,d,e) 
{
    showProgressBar(false,true);
    if(typeof(a) != "undefined"){
    TT_a=a;
    }
    if(typeof(b) != "undefined"){
    TT_b=b;
    }
    if(typeof(c) != "undefined"&&TT_c==""){
    TT_c=c;      
    }
    if(typeof(d) != "undefined"&&TT_d==""){
    TT_d=d;
    }
    if(typeof(e) != "undefined"&&TT_e==""){
    TT_e=e;
    }
    if(TT_c!=""&&TT_d!=""&&TT_e!="")
    {
     _TT_Week=TT_c.split('$');
    if(_TT_Week.length>0)_TT_Week.splice(_TT_Week.length-1,1);
    _TT_FromTime=TT_d.split('$');
    if(_TT_FromTime.length>0)_TT_FromTime.splice(_TT_FromTime.length-1,1);
     _TT_ToTime=TT_e.split('$');
    if(_TT_ToTime.length>0)_TT_ToTime.splice(_TT_ToTime.length-1,1);
    }
    WebServices.User.Public.GetTeTime($onsuccTT$);
}
function $onsuccTT$(result)
{
     showProgressBar(false,true);    
        TT_TP015 = result[0][0];
        TT_TP017 = result[0][1];
        TT_TP018 = result[0][2];
        TT_TP019 = result[0][3];
        TT_TP020 = result[0][4];
        TT_TP021 = result[0][5];
        TT_TP022 = result[0][6];
        TT_TP023 = result[0][7];
        TT_TP024 = result[0][8];
        TT_C0045 = result[0][9];
        TT_C0044 = result[0][10];
        TT_C0053 = result[0][11];
        TT_TP315 = result[0][12];
        TT_C0050 = result[0][13];
         $("$divIput$").style.display = "none";
       var TT_TimeText="<div><select id='_TT_SWeeks'><option value='0'>"+TT_TP017+"</option><option value='1'>"+TT_TP018+"</option><option value='2'>"+TT_TP019+"</option><option value='3'>"+TT_TP020+"</option><option value='4'>"+TT_TP021+"</option><option value='5'>"+TT_TP022+"</option><option value='6'>"+TT_TP023+"</option>";
       TT_TimeText+="</select> <select id='_TT_secT'onchange='_TT_Oncge(this,\"1\",\"_TT_tsecT\")'>";
       for(var i=0;i<48;i++)
       {
       if(i%2==0)
       {
        if(i>19)
        {
        TT_TimeText+="<option value='"+i/2+":00'>"+i/2+":00</option>";
        }else
        {
           TT_TimeText+="<option value='0"+i/2+":00'>0"+i/2+":00</option>"; 
        }
       }else
       {
       if(i>19)
        {
        TT_TimeText+="<option value='"+(i-1)/2+":30'>"+(i-1)/2+":30</option>";
        }else
        {
          TT_TimeText+="<option value='0"+(i-1)/2+":30'>0"+(i-1)/2+":30</option>";  
        }
       }
       }
       TT_TimeText+="</select> "+TT_TP024+" <span id='_TT_divT'><select id='_TT_tsecT'>";
       for(var i=1;i<49;i++)
       {
       if(i%2==0)
       {
       if(i>19)
        {
           TT_TimeText+="<option value='"+i/2+":00'>"+i/2+":00</option>";
        }else
        {
           TT_TimeText+="<option value='0"+i/2+":00'>0"+i/2+":00</option>";  
        }
       }else
       {
         if(i>19)
        {
        TT_TimeText+="<option value='"+(i-1)/2+":30'>"+(i-1)/2+":30</option>";
        }else
        {
          TT_TimeText+="<option value='0"+(i-1)/2+":30'>0"+(i-1)/2+":30</option>";  
        }
       }
       }
       TT_TimeText+="</select></span> ";
       TT_TimeText+="<a href=\"javascript:void(0);\" onclick='_TT_add()'>"+TT_C0044+"</a></div><div id='_TT_rid'>"
       TT_TimeText+="</div><div class=\"time_button\"><input type=\"button\" value=\""+TT_C0045+"\" class=\"button\" onclick=\"_TT_Save()\" /><span style=\"color: Red;display:none\" id='_TT_Sp'><br/>"+TT_TP315+"</span></div>";
		$ShowSampleTTimeBox$(TT_TimeText);
}
function $ShowSampleTTimeBox$(text)
{
var obj={}
    $ShowMessageBox$(TT_TP015,text,obj,_TT_Empty,300);_TT_SaveTime();
}
function _TT_SaveTime(s)
{
var _TT_showtim='<div class="margin20"><table width="200" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">';
var _TT_timeLen = _TT_Week.length;
for(var i=0; i<_TT_timeLen;i++)
    {
            switch (_TT_Week[i])
            {
            case "0" :
            _TT_showtim+="<tr><td bgcolor=\"#f8f8f8\" align=\"center\">"+TT_TP017+"</td><td >"+_TT_FromTime[i]+"-"+_TT_ToTime[i]+"</td><td  align=\"right\"><a href=\"javascript:void(0);\"  onclick=\"_TT_del("+i+")\">"+TT_C0050+"</a></td></tr>";    
            break;
            case "1" :
            _TT_showtim+="<tr><td bgcolor=\"#f8f8f8\" align=\"center\">"+TT_TP018+"</td><td >"+_TT_FromTime[i]+"-"+_TT_ToTime[i]+"</td><td  align=\"right\"><a href=\"javascript:void(0);\"  onclick=\"_TT_del("+i+")\">"+TT_C0050+"</a></td></tr>";
            break;
            case "2" :
            _TT_showtim+="<tr><td bgcolor=\"#f8f8f8\" align=\"center\">"+TT_TP019+"</td><td >"+_TT_FromTime[i]+"-"+_TT_ToTime[i]+"</td><td  align=\"right\"><a href=\"javascript:void(0);\"  onclick=\"_TT_del("+i+")\">"+TT_C0050+"</a></td></tr>"; 
            break;
            case "3" :
            _TT_showtim+="<tr><td bgcolor=\"#f8f8f8\" align=\"center\">"+TT_TP020+"</td><td >"+_TT_FromTime[i]+"-"+_TT_ToTime[i]+"</td><td  align=\"right\"><a href=\"javascript:void(0);\"  onclick=\"_TT_del("+i+")\">"+TT_C0050+"</a></td></tr>";
            break;
            case "4" :
            _TT_showtim+="<tr><td bgcolor=\"#f8f8f8\" align=\"center\">"+TT_TP021+"</td><td >"+_TT_FromTime[i]+"-"+_TT_ToTime[i]+"</td><td  align=\"right\"><a href=\"javascript:void(0);\" onclick=\"_TT_del("+i+")\">"+TT_C0050+"</a></td></tr>";
            break;
            case "5" :
            _TT_showtim+="<tr><td bgcolor=\"#f8f8f8\" align=\"center\">"+TT_TP022+"</td><td >"+_TT_FromTime[i]+"-"+_TT_ToTime[i]+"</td><td  align=\"right\"><a href=\"javascript:void(0);\" onclick=\"_TT_del("+i+")\">"+TT_C0050+"</a></td></tr>";
            break;
            case "6" :
            _TT_showtim+="<tr><td bgcolor=\"#f8f8f8\" align=\"center\">"+TT_TP023+"</td><td >"+_TT_FromTime[i]+"-"+_TT_ToTime[i]+"</td><td  align=\"right\"><a href=\"javascript:void(0);\"  onclick=\"_TT_del("+i+")\">"+TT_C0050+"</a></td></tr>";
            break;
            }
    }
        _TT_showtim+="</table></div>";
        if(typeof(s) != "undefined"){
     $(s).innerHTML=_TT_showtim.replace(/<td  align=[^>]*><a ([\u0001-\uFFFF]*?)<\/td>/gi,"");
      $EndMessageBox$();
    }else
    {
       $('_TT_rid').innerHTML=_TT_showtim;
       }
       showProgressBar(false);
}
function _TT_del(i)
{
showProgressBar(true);
 _TT_Week.splice(i,1);
 _TT_FromTime.splice(i,1);
 _TT_ToTime.splice(i,1);
 _TT_SaveTime();

}
function _TT_Empty()
{
    $EndMessageBox$();
}
//限制时间tp为类型1为选择FromTimes其他为ToTimes
function _TT_Oncge(chge,tp,sid)
{
var TT_Timtext="<select id='_TT_tsecT'>";
if(tp=="1")
{
    for(var i=1;i<49;i++)
       {
           if(i%2==0)
           {
              if(i>19)
            {
             TT_Timtext+="<option value='"+i/2+":00'>"+i/2+":00</option>";
             if(chge.value==(i/2+":00"))
             {
                 TT_Timtext="<select id='_TT_tsecT'> ";
             }
             }else
             {
             TT_Timtext+="<option value='0"+i/2+":00'>0"+i/2+":00</option>"; 
             if(chge.value==("0"+i/2+":00"))
             {
                 TT_Timtext="<select id='_TT_tsecT'> ";
             }  
             }
             
           }else
           {
                if(i>19)
                {
                TT_Timtext+="<option value='"+(i-1)/2+":30'>"+(i-1)/2+":30</option>";
                if(chge.value==((i-1)/2+":30"))
                 {
                 TT_Timtext="<select id='_TT_tsecT'> ";
                 }
                }else
                {
                  TT_Timtext+="<option value='0"+(i-1)/2+":30'>0"+(i-1)/2+":30</option>"; 
                  if(chge.value==("0"+(i-1)/2+":30"))
                 {

                 TT_Timtext="<select id='_TT_tsecT'> ";
                 } 
                }
                
           }
       
       }
}
TT_Timtext+="</select>";
 //$('_TT_tsecT').innerHTML=TT_Timtext;   
 $('_TT_divT').innerHTML=TT_Timtext;
}
function _TT_add()
{
    _TT_Week.push($('_TT_SWeeks').value);
    _TT_FromTime.push($('_TT_secT').value);
    _TT_ToTime.push($('_TT_tsecT').value);
    _TT_SaveTime();
}
function _TT_Save()
{
TT_c="";
TT_d="";
TT_e="";
$('_TT_Sp').style.display="none";
      var _TT_allT="";
    if(_TT_Week.length==0)
    {
        $('_TT_Sp').style.display="";
        return;
    }
    
    var _TT_allT=""; 
    var _TT_Aarr=new Array();

    for(var i=0;i<_TT_Week.length;i++)
    {
       _TT_allT+=_TT_Week[i]+'$'+_TT_FromTime[i]+'$'+_TT_ToTime[i]+'@';
    }
    
    _TT_Aarr=_TT_allT.split('@');
    if(_TT_Aarr.length>1)
    {
     _TT_Aarr.unique();
     }
       _TT_Week.length=0;
       _TT_FromTime.length=0;
       _TT_ToTime.length=0;
     for(var i=0;i<_TT_Aarr.length-1;i++)
    {
    // Weeks
    _TT_Week.push(_TT_Aarr[i].toString().split('$')[0])
     TT_c+=_TT_Aarr[i].toString().split('$')[0]+'$';
    //  FromTimes
    _TT_FromTime.push(_TT_Aarr[i].toString().split('$')[1])
     TT_d+=_TT_Aarr[i].toString().split('$')[1]+'$';
    // ToTimes
    _TT_ToTime.push(_TT_Aarr[i].toString().split('$')[2])
     TT_e+=_TT_Aarr[i].toString().split('$')[2]+'$';
    }
    _TT_SaveTime(TT_b);
}
Array.prototype.unique   =   function()  
  {  
      var   a   =   {};   for(var   i=0;   i<this.length;   i++)  
      {  
          if(typeof   a[this[i]]   ==   "undefined")  
              a[this[i]]   =   1;  
      }  
      this.length   =   0;  
      for(var   i   in   a)  
          this[this.length]   =   i;  
      return   this;  
}